﻿#include "fcgiplus.hpp"
#include "eiendb.hpp"
#include "eiennet.hpp"
#include "eiengd.hpp"
#include "eienexpr.hpp"
#include "eientpl.hpp"
#include "fcgiserv.hpp"
#include <iostream>
using namespace std;
using namespace winux;
using namespace eiendb;
using namespace eiennet;
using namespace eiengd;
using namespace eienexpr;
using namespace eientpl;
using namespace fcgi;

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <termios.h>

// 清除屏幕
#define CLEAR() printf("\033[2J")
// 上移光标
#define MOVEUP(x) printf("\033[%dA", (x))
// 下移光标
#define MOVEDOWN(x) printf("\033[%dB", (x))
// 左移光标
#define MOVELEFT(y) printf("\033[%dD", (y))
// 右移光标
#define MOVERIGHT(y) printf("\033[%dC",(y))
// 定位光标
#define MOVETO(x,y) printf("\033[%d;%dH", (x), (y))
// 光标复位
#define RESET_CURSOR() printf("\033[H")
// 隐藏光标
#define HIDE_CURSOR() printf("\033[?25l")
// 显示光标
#define SHOW_CURSOR() printf("\033[?25h")
//反显
#define HIGHT_LIGHT() printf("\033[7m")
#define UN_HIGHT_LIGHT() printf("\033[27m")


class TerminalDisplay {
public:
    TerminalDisplay() :
        __cursorCol(0),
        __cursorRow(0)
    {
        getSize();
        moveTo(__cursorCol,__cursorRow);
    }
    void getSize(){
        //TIOCSWINSZ命令可以将此结构的新值存放到内核中
        ioctl(STDIN_FILENO,TIOCGWINSZ,&__winsize);
    }
    
    inline int width() const {
        return __winsize.ws_col;
    }
    inline int height() const {
        return __winsize.ws_row;
    }
    void moveTo( int col, int row ) {
        __cursorCol = col;
        __cursorRow = row;
        MOVETO(col,row);
    }
    void clear(){
        CLEAR();
    }
    void out( String const& str ) {
	    write(1,str.c_str(),str.size());
    }

private:
    struct winsize __winsize;
    int __cursorCol;
    int __cursorRow;
};

int main( int argc, char const * argv[] )
{
#if defined(__GNUC__) && !defined(WIN32) // on linux
    SetLocale::Set("zh_CN.UTF-8");
#endif
    winux::SetLocale __loc__;
    try
    {
// `display.inc.ecp` embed code is empty!



TerminalDisplay display;

display.getSize();

display.clear();

while(1){
    display.out( "\033[15;5H                                  " );
    display.out( "\033[15;5HhelloDisplay!!!Yes,this is display" );
}

// cout << Format( "%d, %d", display.width(), display.height() );

    }
    catch ( std::exception const & e )
    {
        cout << e.what() << endl;
    }
    catch (...)
    {
        cout << "Unknown error" << endl;
    }
    return 0;
}

